<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <el-tabs
      v-model="activeName"
      @tab-click="handleClick"
      type="card"
      class="commonTab"
    >
      <el-tab-pane label="花名册修改" name="first"></el-tab-pane>
      <!-- <el-tab-pane label="其他" name="second"></el-tab-pane> -->
    </el-tabs>
    <div class="mainCon">
      <el-row class="searchBox searchInputWidth">
        <el-form :inline="true" :model="filterField" ref="accountForm">
          <el-col :lg="8" :xl="6">
            <el-form-item label="人员姓名" class="row-padding-bottom">
              <el-input
                placeholder="请输入姓名"
                clearable
                v-model="filterField.name"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="身份证号" class="row-padding-bottom">
              <el-input
                placeholder="请输入身份证号"
                clearable
                v-model="filterField.idcard"
              ></el-input>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="操作时间">
                <timeSelection
                  @getStartTimeValue="getStartTimeValue"
                  @getEndTimeValue="getEndTimeValue"
                ></timeSelection>
              </el-form-item>
            </el-col>
          </template>
          <el-form-item>
            <a
              @click="toggleAdvanced"
              style="margin-left: 40px; color: #409eff; cursor: pointer"
              class="btnColor"
            >
              {{ advanced ? '收起' : '展开' }}
              <i
                :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
              ></i>
            </a>
            <el-button
              type="primary"
              icon="icon iconfont iconchazhao1"
              @click="searchList"
              class="searchBtn"
            >
              <span>搜索</span>
            </el-button>
            <exportBtn
              :dataLen="tableData.length"
              :filterField="filterField"
              api="api-e/employee/log/export"
              responseType="get"
            ></exportBtn>
          </el-form-item>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <!-- 列表 -->
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
        >
          <el-table-column label="修改前" align="center">
            <el-table-column
              align="center"
              prop="name"
              label="姓名"
              width="120"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="idcard"
              label="身份证号"
              width="180"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="sexValue"
              label="性别"
              min-width="100"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="birthday"
              label="出生日期"
              min-width="140"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="nationalityValue"
              label="民族"
              min-width="100"
              :formatter="formatTd"
            ></el-table-column>
          </el-table-column>
          <el-table-column label="修改后" align="center">
            <el-table-column
              align="center"
              prop="nameAfter"
              label="姓名"
              width="120"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="idcardAfter"
              label="身份证号"
              width="180"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="sexValueAfter"
              label="性别"
              min-width="100"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="birthdayAfter"
              label="出生日期"
              min-width="140"
              :formatter="formatTd"
            ></el-table-column>
            <el-table-column
              align="center"
              prop="nationalValueAfter"
              label="民族"
              min-width="100"
              :formatter="formatTd"
            ></el-table-column>
          </el-table-column>
          <el-table-column
            prop="operatorName"
            label="操作人"
            fixed="right"
            width="120"
            align="center"
            :formatter="formatTd"
          >
          </el-table-column>
          <el-table-column align="left" label="操作" fixed="right" width="120">
            <template slot-scope="scope">
              <el-link type="primary" @click="editStatus(scope.row.id)"
                >查看详情</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
        ></Pagination>
      </div>
    </div>
    <el-dialog
      title="花名册信息修改详情"
      :visible.sync="addDialog"
      @close="closeDialog('formData')"
      :close-on-click-modal="false"
      :modal-append-to-body="false"
      width="700px"
      class="tipsDia"
    >
      <div class="secondaryTitle secondaryTitleTheme">花名册信息修改前</div>
      <p class="infoItem"><span>姓名：</span>{{ currentInfos.name }}</p>
      <p class="infoItem"><span>身份证号码：</span>{{ currentInfos.idcard }}</p>
      <p class="infoItem"><span>性别：</span>{{ currentInfos.sexValue }}</p>
      <p class="infoItem"><span>出生日期：</span>{{ currentInfos.birthday }}</p>
      <p class="infoItem">
        <span>民族：</span>{{ currentInfos.nationalityValue }}
      </p>
      <p class="infoItem"><span>家庭住址：</span>{{ currentInfos.address }}</p>
      <div class="secondaryTitle secondaryTitleTheme secondaryTitle1">
        花名册信息修改后
      </div>
      <p class="infoItem"><span>姓名：</span>{{ currentInfos.nameAfter }}</p>
      <p class="infoItem">
        <span>身份证号码：</span>{{ currentInfos.idcardAfter }}
      </p>
      <p class="infoItem">
        <span>性别：</span>{{ currentInfos.sexValueAfter }}
      </p>
      <p class="infoItem">
        <span>出生日期：</span>{{ currentInfos.birthdayAfter }}
      </p>
      <p class="infoItem">
        <span>民族：</span>{{ currentInfos.nationalValueAfter }}
      </p>
      <p class="infoItem">
        <span>家庭住址：</span>{{ currentInfos.addressAfter }}
      </p>
      <p class="infoItem">
        <span>身份证照片附件：</span
        ><el-link
          type="primary"
          @click="checkLook(currentInfos.idCardPhotoPath)"
          >查看</el-link
        >
        <el-image
          id="publicSignBox"
          class="previewImg"
          style="width: 0px; height: 0px"
          ref="imgs"
          :src="src"
          :preview-src-list="[src]"
        >
        </el-image>
      </p>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click.native="closeDialog('formData')"
          v-sdc
          :loading="isSaveLoading"
          class="save"
          >关闭</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import scrollTable from '@/mixin/scrollTable.js'
export default {
  mixins: [scrollTable],
  data() {
    return {
      src: '',
      advanced: false,
      titleText: '数据修改记录',
      activeName: 'first',
      filterField: {
        name: '',
        idcard: '',
        startDate: '',
        endDate: '',
      },
      tableData: [],
      loading: true,
      isShow: false,
      requestUrl: 'api-e/employee/log/list',
      addDialog: false,
      currentInfos: {
        name: '',
        nameAfter: '',
        idcard: '',
        idcardAfter: '',
        sexValue: '',
        sexValueAfter: '',
        birthday: '',
        birthdayAfter: '',
        nationalityValue: '',
        nationalValueAfter: '',
        address: '',
        addressAfter: '',
      },
    }
  },
  mounted() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  activated() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  methods: {
    checkLook(url) {
      this.src = url
      setTimeout(() => {
        $('#publicSignBox').click()
      }, 300)
    },
    searchList() {
      this.$nextTick(function () {
        this.$refs.pagination.getTableListData()
      })
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    handleClick() {},
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      }
    },
    getStartTimeValue(val) {
      if (val) {
        this.filterField.startDate = val
      } else {
        this.filterField.startDate = ''
      }
    },
    getEndTimeValue(val) {
      if (val) {
        this.filterField.endDate = val
      } else {
        this.filterField.endDate = ''
      }
    },
    editStatus(id) {
      this.axios.post('api-e/employee/log/detail', { id }).then((res) => {
        if (!res.data.hasError) {
          this.currentInfos = res.data.result
          this.addDialog = true
        } else {
          this.$message({
            message: res.data.errorMsg,
            type: 'warning',
          })
        }
      })
    },
    closeDialog(ele) {
      this.addDialog = false
    },
  },
}
</script>
<style lang="less" scoped>
.secondaryTitle {
  margin-bottom: 10px;
}
.secondaryTitle1 {
  margin-top: 20px;
}
.infoItem {
  padding-left: 14px;
  line-height: 26px;
  color: #666;
  span {
    color: #333;
  }
}
</style>
